package ru.cod.rs.service;

import ru.cod.rs.manager.AbstractManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public abstract class AbstractManagerImpl extends Thread implements AbstractManager {
	
	protected Context context;
	protected boolean ready=false;
	
	public AbstractManagerImpl(Context context) {
		super();
		this.context=context;	
	}
	public AbstractManagerImpl() {
		super();
	}
	public void pause() {
		ready=false;
	}

	public void goOn() {
		ready=true;
	}
	
	@Override
	public void run() {
		Log.i("RUN METHOD IN THREAD OF ABSTRACTMANAGER","");
		while(ready) {
			
			if(isSkip()) {
				continue;
			}
			
			execute();
			
			try {
				Thread.sleep(50);
			} catch(InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public abstract void execute();
	public abstract boolean isSkip();
	
	protected Bitmap getImage(int id) {
		return BitmapFactory.decodeResource(context.getResources(),id);
	}
	/**
	 * @return the context
	 */
	protected Context getContext() {
		return context;
	}
	
}
